'use strict';

/* global resetActive addClass removeClass
*/

// 给性别加上绑定函数
function bindtag() {
	var male = document.getElementsByClassName('male')[0];
	var female = document.getElementsByClassName('female')[0];
	male.addEventListener("click", function () {
		resetActive();
		addClass(male, 'active');
	});
	female.addEventListener("click", function () {
		resetActive();
		addClass(female, 'active');
	});
}
bindtag();

// 检测容器下面所有选中的checkbox并取得他们的id，给他们同样id的容器加上active
function addActive() {
	var tagparent = document.getElementsByClassName('many')[0];
	var tag = tagparent.getElementsByTagName('input');
	var length = tag.length;
	for (var i = 0; i != length; i++) {
		if (tag[i].checked === true) {
			var tagid = tag[i].id;
			var tagdom = document.getElementsByClassName(tagid)[0];
			addClass(tagdom, 'active');
		} else {
			var _tagid = tag[i].id;
			var _tagdom = document.getElementsByClassName(_tagid)[0];
			removeClass(_tagdom, 'active');
		}
	}
}

document.addEventListener('click', function () {
	addActive();
});